package com.atguigu.day09;

import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
import org.apache.flink.table.catalog.hive.HiveCatalog;

public class Flink07_HiveCataLog {
    public static void main(String[] args) {
        System.setProperty("HADOOP_USER_NAME", "atguigu");
        //1.获取流的执行环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        env.setParallelism(1);

        //2.获取表的执行环境
        StreamTableEnvironment tableEnv = StreamTableEnvironment.create(env);

        //3.创建HiveCatalog
        String name = "hiveCatalog";
        String defaultDatabase = "flink_test";
        String conf = "c:/conf";
        HiveCatalog hiveCatalog = new HiveCatalog(name, defaultDatabase, conf);

        //4.注册Catalog
        tableEnv.registerCatalog(name, hiveCatalog);

        //5.可以设置使用哪个Catalog以及使用哪个数据库
        tableEnv.useCatalog(name);
        tableEnv.useDatabase(defaultDatabase);

        //6.查询hive中表的数据
        tableEnv.executeSql("select * from stu").print();
    }
}
